home *** CD-ROM | disk | FTP | other *** search
/ Minami 78 / MINAMI78.iso / Extra / winamp53.exe / $R0 / Winamp Modern / scripts / drawer.m < prev    next >
Text File  |  2005-09-15  |  35KB  |  997 lines

  1. // -----------------------------------------------------------------------
  2. // Generic Video/Vis Application Drawer, by Nullsoft.
  3. //
  4. // Please #include this script, and override the appropriate events 
  5. // (see end of file), rather than modifying this script into your own 
  6. // version. 
  7. //
  8. // *You should not have to edit this file*, it's just a bad idea, period. 
  9. // If you need something that is not supported in this version, we 
  10. // recommend that you contact Nullsoft to suggest the feature.
  11. //
  12. // Satisfying user experience depends on *fully working* scripts, if you 
  13. // insist on taking this file and modifying it for yourself, be sure to 
  14. // *thoroughly* test its behavior once you are done.
  15. //
  16. // If you do add a feature, please contact us so that your extention can 
  17. // be made available to others without each skin developper making its 
  18. // own (potentially broken) implementation.
  19. //
  20. // Note: this script requires mc 1.1.2+ to compile, and wa5b3+ / wa3build500+
  21. // to run.
  22. // -----------------------------------------------------------------------
  23.  
  24. #ifndef included
  25. #error This script can only be compiled as a #include
  26. #endif
  27.  
  28. #include <lib/std.mi>
  29. #include <lib/config.mi>
  30.  
  31. // call these -- the first two are mandatory
  32. Function initDrawer(Layout lay, String id); // call in your onScriptLoaded();
  33. Function shutdownDrawer();                  // call in your onScriptUnloading();
  34. Function openDrawer();                      // opens the drawer to the last page unless video plays, in which case it opens to it. does animations according to attribs
  35. Function openDrawerForVideo();              // opens the drawer to the video page, does animations according to attribs
  36. Function openDrawerForVis();                // opens the drawer to the vis page, does animations according to attribs
  37. Function openDrawerForNothing();            // opens the drawer without putting anything in it, does animations according to attribs
  38. Function closeDrawer();                     // closes the drawer, does animations according to attribs
  39. Function detachVis();
  40. Function attachVis();
  41. Function detachVideo();
  42. Function attachVideo();
  43. Function switchToVis();
  44. Function switchToVideo();
  45. Function Int getDrawerState();              // returns OPEN or CLOSED
  46. Function Int getDrawerContent();            // returns CONTENT_VIDEO, CONTENT_VIS or CONTENT_NOTHING
  47. Function maximizeWindow();
  48. Function restoreWindow();
  49. Function Int isDrawerToTop();               // returns 1 if the drawer will open to the top or will close from the top, rather than the normal to/from bottom
  50. // whenever the main window is resized while its drawer is closed, you should compute a new layout 
  51. // height for the next opening of the drawer, this will avoid opening to a gigantic height after 
  52. // closing a big video and resizing the player horizontally. return -1 if you do not want this feature
  53. Function Int getDrawerOpenAutoHeight(int layoutwidth); 
  54.  
  55. // implement these -- mandatory
  56. Function WindowHolder getVideoWindowHolder();
  57. Function WindowHolder getVisWindowHolder();
  58. Function Int getDrawerClosedHeight();
  59. Function Int getDefaultDrawerOpenHeight();
  60.  
  61. // override these -- optional
  62. Function onBeforeOpeningDrawer();
  63. Function onBeforeClosingDrawer();
  64. Function onDoneOpeningDrawer();
  65. Function onDoneClosingDrawer();
  66. Function onShowVis();
  67. Function onHideVis();
  68. Function onShowVideo();
  69. Function onHideVideo();
  70. Function onAttachVideo();
  71. Function onDetachVideo();
  72. Function onAttachVis();
  73. Function onDetachVis();
  74. Function onBeforeMaximize();
  75. Function onAfterMaximize();
  76. Function onBeforeRestore();
  77. Function onAfterRestore();
  78. Function onCancelMaximize();
  79.  
  80. // bind these -- mandatory (they don't have to be exposed in the menus)
  81. Global ConfigAttribute __drawer_directiontop_attrib;
  82. Global ConfigAttribute __scrolldrawerattrib;
  83. Global ConfigAttribute __drawer_directionbypass_attrib;
  84. Global ConfigAttribute __vis_detach_attrib;
  85. Global ConfigAttribute __video_detach_attrib;
  86.  
  87. // -----------------------------------------------------------------------
  88.  
  89. #define VIDEO_GUID "{F0816D7B-FFFC-4343-80F2-E8199AA15CC3}"
  90. #define VIS_GUID "{0000000A-000C-0010-FF7B-01014263450C}"
  91.  
  92. // this is used to temporarilly disable playback stop on video window close, in case it's set
  93. #define SKINTWEAKS_CFGPAGE "{0542AFA4-48D9-4c9f-8900-5739D52C114F}"
  94.  
  95. #define DEBUG
  96.  
  97. #define FALSE 0
  98. #define TRUE -1
  99.  
  100. #define CLOSED 0
  101. #define OPEN   1
  102.  
  103. #define DIRECTION_NONE    0
  104. #define DIRECTION_OPENING 1
  105. #define DIRECTION_CLOSING 2
  106.  
  107. #define CONTENT_NOTHING 0
  108. #define CONTENT_VIDEO   1
  109. #define CONTENT_VIS     2
  110.  
  111. #define DETACHED_VIS   1
  112. #define DETACHED_VIDEO 2
  113.  
  114. // avoid calling these functions directly. if you do so, be sure to know what
  115. // you're doing, and to test your script thoroughly.
  116.  
  117. Function drawer_expandWindow(int withdrawer);
  118. Function drawer_reduceWindow(int withdrawer);
  119. Function drawer_showWindowContent();
  120. Function drawer_hideWindowContent();
  121. Function drawer_hideVis();
  122. Function drawer_showVis();
  123. Function drawer_hideVideo();
  124. Function drawer_showVideo();
  125. Function drawer_dc_showVis();
  126. Function drawer_dc_showVideo();
  127. Function drawer_dc_hideVis();
  128. Function drawer_dc_hideVideo();
  129. Function drawer_dc_linkup_showVis();
  130. Function drawer_dc_linkup_showVideo();
  131. Function drawer_doDetachVis();
  132. Function drawer_doAttachVis();
  133. Function drawer_doDetachVideo();
  134. Function drawer_doAttachVideo();
  135. Function drawer_disablePSOVC();
  136. Function drawer_enablePSOVC();
  137. Function drawer_linkup_showVis();
  138. Function drawer_linkup_showVideo();
  139. Function drawer_doMaximizeWindow(int notif);
  140.  
  141. Global Int __drawer_direction;
  142.  
  143. Global Timer __callbackTimer;
  144. Global Int __callback_vis_show, __callback_video_show, __callback_vis_hide, __callback_video_hide;
  145. Global Timer __callbackTimer2;
  146. Global Int __callback2_what;
  147. Global Timer __PSOVCTimer;
  148. Global Int __bypasscancel;
  149. Global Int __isinited;
  150.  
  151. Global Int __hiding_video, __hiding_vis, __showing_vis, __showing_video;
  152. Global Int __last_forcedbottom, __last_forcedtop;
  153. Global Timer __tempDisable;
  154.  
  155. Global Layout __main;
  156. Global Container __maincontainer;
  157.  
  158. Global String __myname;
  159. Global Int __windowshade_openvid;
  160. Global Int __windowshade_openvis;
  161.  
  162. Global int __maximized;
  163. Global int __oldx,__oldy,__oldw,__oldh;
  164.  
  165. // -----------------------------------------------------------------------
  166. initDrawer(Layout lay, String name) {
  167.     // todo: test all attribs assigned
  168.  
  169.     __isinited = 0;
  170.  
  171.     __main = lay;
  172.     __maincontainer = __main.getContainer();
  173.  
  174.     if (name == "") __myname = "Drawer";
  175.     else __myname = name;
  176.     __drawer_direction = DIRECTION_NONE;
  177.  
  178.     drawer_hideVis();
  179.     drawer_hideVideo();
  180.  
  181.     __callbackTimer = new Timer;
  182.     __callbackTimer.setDelay(1);
  183.     __callbackTimer2 = new Timer;
  184.     __callbackTimer2.setDelay(1);
  185.     __PSOVCTimer = new Timer;
  186.     __PSOVCTimer.setDelay(1000);
  187.     __tempDisable = new Timer;
  188.     __tempDisable.setDelay(50);
  189.  
  190.     __maximized = getPrivateInt("winamp5", __myname+"Maximized", 0);
  191.     if (__maximized) {
  192.       onBeforeMaximize();
  193.       onAfterMaximize();
  194.     }
  195.  
  196.     __oldx=getPrivateInt("winamp5", __myname+"ox", 0);
  197.     __oldy=getPrivateInt("winamp5", __myname+"oy", 0);
  198.     __oldw=getPrivateInt("winamp5", __myname+"ow", 0);
  199.     __oldh=getPrivateInt("winamp5", __myname+"oh", 0);
  200.     __last_forcedtop = getPrivateInt("winamp5", __myname+"ForcedTop", 0);
  201.     __last_forcedbottom = getPrivateInt("winamp5", __myname+"ForcedBottom", 0);
  202. }
  203.  
  204. // -----------------------------------------------------------------------
  205. shutdownDrawer() {
  206.     delete __callbackTimer;
  207.     delete __callbackTimer2;
  208.     delete __PSOVCTimer;
  209.     delete __tempDisable;
  210. }
  211.  
  212. // -----------------------------------------------------------------------
  213. Int isDrawerToTop() {
  214.   int fromtop = 0;
  215.   if (__drawer_directiontop_attrib.getData() =="1") fromtop = 1;
  216.   if (__drawer_directionbypass_attrib.getData() == "0") return fromtop;
  217.  
  218.   int curstate = getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  219.   if (curstate != CLOSED) return __last_forcedtop;
  220.  
  221.   int h=getPrivateInt("winamp5", __myname+"Height", getDefaultDrawerOpenHeight());
  222.   if (h == getDrawerClosedHeight()) h = getDefaultDrawerOpenHeight();
  223.   if (__maximized) h = getViewportHeight()+__main.getSnapAdjustBottom();
  224.  
  225.   __last_forcedbottom = 0;
  226.   __last_forcedtop = 0;
  227.  
  228.   // clienttoscreen auto adjusts for render ratio
  229.   if (fromtop) {
  230.     int y = __main.getGuiY();
  231.     int curh = __main.clientToScreenH(__main.getGuiH());
  232.     if (y + curh < __main.clientToScreenH(h) + getViewportTop()) {
  233.       int offset = __main.getSnapAdjustBottom();
  234.       if (!(y + __main.clientToScreenH(h-offset) > getViewPortTop()+getViewPortHeight())) {
  235.         __last_forcedbottom = 1;
  236.         return 0;
  237.       }
  238.     }
  239.   } else {
  240.     int offset = __main.getSnapAdjustBottom();
  241.     int y = __main.getGuiY();
  242.     if (y + __main.clientToScreenH(h-offset) > getViewPortTop()+getViewPortHeight()) {
  243.       int curh = __main.clientToScreenH(__main.getGuiH());
  244.       if (!(y + curh < __main.clientToScreenH(h) + getViewportTop())) {
  245.         __last_forcedtop = 1;
  246.         return 1;
  247.       }
  248.     }
  249.   }
  250.   return fromtop;
  251. }
  252.  
  253. // -----------------------------------------------------------------------
  254. __main.onTargetReached() {
  255.     unlockUI();
  256.     if (__drawer_directiontop_attrib.getData() =="1") __main.reverseTarget(0);
  257.     if (__drawer_direction == DIRECTION_OPENING) {
  258.         setPrivateInt("winamp5", __myname+"OpenState", OPEN);
  259.         drawer_showWindowContent();
  260.         onDoneOpeningDrawer();
  261.     } else if (__drawer_direction == DIRECTION_CLOSING) {
  262.         setPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  263.         onDoneClosingDrawer();
  264.     }
  265.     __drawer_direction = DIRECTION_NONE;
  266. }
  267.  
  268. // -----------------------------------------------------------------------
  269. drawer_expandWindow(int withdrawer) {
  270.     int curstate = getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  271. #ifdef DEBUG
  272.     debugstring("expand - curstate = " + integertostring(curstate), 0);
  273. #endif
  274.     if (curstate == OPEN) {
  275.       drawer_showWindowContent();
  276.       onBeforeOpeningDrawer();
  277.       onDoneOpeningDrawer();
  278.       return;
  279.     }
  280.     int fromtop = isDrawerToTop();
  281.     setPrivateInt("winamp5", __myname+"OpenState", OPEN);
  282.  
  283.     int h=getPrivateInt("winamp5", __myname+"Height", getDefaultDrawerOpenHeight());
  284.     if (h == getDrawerClosedHeight()) h = getDefaultDrawerOpenHeight();
  285.     if (__maximized) h = getViewportHeight()+__main.getSnapAdjustBottom();
  286.     int w = __main.getGuiW();
  287.  
  288.     if (h == __main.getHeight()) withdrawer = 0;
  289.  
  290.     onBeforeOpeningDrawer();
  291.  
  292.     int delay = 0;
  293.     if (!__main.isLayoutAnimationSafe()) withdrawer = 0;
  294.     if (withdrawer && StringToInteger(__scrolldrawerattrib.getData())) delay = 1;
  295.  
  296.     __drawer_direction = DIRECTION_OPENING;
  297.     __main.setTargetX(__main.getGuiX());
  298.     __main.setTargetY(__main.getGuiY());
  299.     __main.setTargetW(w);
  300.     __main.setTargetH(h);
  301.     __main.reverseTarget(fromtop);
  302.     __main.setTargetSpeed(delay);
  303.     __main.gotoTarget();
  304.     lockUI();
  305.  
  306.     if (!__maximized)
  307.       setPrivateInt("winamp5", __myname+"Height", h);
  308.     setPrivateInt("winamp5", __myname+"ForcedBottom", __last_forcedBottom);
  309.     setPrivateInt("winamp5", __myname+"ForcedTop", __last_forcedtop);
  310. }
  311.  
  312. // -----------------------------------------------------------------------
  313. drawer_reduceWindow(int withdrawer) {
  314. #ifdef DEBUG
  315.     debugstring("reduce", 0);
  316. #endif
  317.     drawer_hideVis();
  318.     drawer_hideVideo();
  319.     setPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  320.     if (__drawer_direction == DIRECTION_NONE && !__maximized) { // avoid saving new size if we're currenly opening
  321.         int h=__main.getHeight();
  322.         setPrivateInt("winamp5", __myname+"Height", h);
  323.     }
  324.  
  325.     drawer_hideWindowContent();
  326.     onBeforeClosingDrawer();
  327.  
  328.     int fromtop=0;
  329.     if (__drawer_directiontop_attrib.getData() =="1") fromtop = 1;
  330.  
  331.     int delay = 0;
  332.     if (!__main.isLayoutAnimationSafe()) withdrawer = 0;
  333.     if (withdrawer && StringToInteger(__scrolldrawerattrib.getData())) delay = 1;
  334.  
  335.     if (__drawer_directionbypass_attrib.getData() == "1") {
  336.         if (__last_forcedtop) fromtop = 1; 
  337.         if (__last_forcedbottom) fromtop = 0;
  338.     }
  339.  
  340.     __drawer_direction = DIRECTION_CLOSING;
  341.     __main.setTargetX(__main.getGuiX());
  342.     __main.setTargetY(__main.getGuiY());
  343.     __main.setTargetW(__main.getGuiW());
  344.     __main.setTargetH(getDrawerClosedHeight());
  345.     __main.reverseTarget(fromtop);
  346.     __main.setTargetSpeed(delay);
  347.     __main.gotoTarget();
  348.     lockUI();
  349.     __last_forcedtop = 0;
  350.     __last_forcedbottom = 0;
  351.     setPrivateInt("winamp5", __myname+"ForcedBottom", 0);
  352.     setPrivateInt("winamp5", __myname+"ForcedTop", 0);
  353. }
  354.  
  355. // -----------------------------------------------------------------------
  356. openDrawer() {
  357.     if (__tempDisable.isRunning()) return;
  358.     __tempDisable.start();
  359.     int s = getStatus();
  360.     if (s == STATUS_PLAYING || s == STATUS_PAUSED) {
  361.         if (!isVideo()) {
  362.             if (__vis_detach_attrib.getData() == "0") {
  363.                 openDrawerForVis();
  364.             } else if (__video_detach_attrib.getData() == "0") {
  365.                 openDrawerForVideo();
  366.             } else {
  367.                 openDrawerForNothing();
  368.             }
  369.         } else {
  370.             if (__video_detach_attrib.getData() == "0") {
  371.                 openDrawerForVideo();
  372.             } else if (__vis_detach_attrib.getData() == "0") {
  373.                 openDrawerForVis();
  374.             } else {
  375.                 openDrawerForNothing();
  376.             }
  377.         }
  378.     } else {
  379.         int Window_Content=getPrivateInt("winamp5", __myname+"State", CONTENT_VIS);
  380.         if (window_content == CONTENT_VIS && __vis_detach_attrib.getData() == "0") {
  381.             openDrawerForVis();
  382.         } else if (window_content == CONTENT_VIDEO && __video_detach_attrib.getData() == "0") {
  383.             openDrawerForVideo();
  384.         } else if (__vis_detach_attrib.getData() == "0") {
  385.             openDrawerForVis();
  386.         } else if (__video_detach_attrib.getData() == "0") {
  387.             openDrawerForVideo();
  388.         } else {
  389.             openDrawerForNothing();
  390.         }
  391.     }
  392. }
  393.  
  394. // -----------------------------------------------------------------------
  395. closeDrawer() {
  396.     drawer_reduceWindow(1);
  397. }
  398.  
  399. // -----------------------------------------------------------------------
  400. // The heart of the machine, here we detect when a window wants to open
  401. // or close, and we decide what to do about it. When we return FALSE, the
  402. // window performs what it notified us about. When we return TRUE, the
  403. // showing/hiding of the window is cancelled, and it is now up to us to
  404. // show or hide the window once we're done with our animations.
  405. // To show the window ourselves, we later show a windowholder with the
  406. // autoopen="1" param, and to hide the window, we simply hide the
  407. // windowholder, and its autoclose="1" param will do the rest
  408. // -----------------------------------------------------------------------
  409. System.onGetCancelComponent(String guid, boolean goingvisible) {
  410. #ifdef DEBUG
  411.     DebugString("+", 0);
  412. #endif
  413.     if (__bypasscancel) return FALSE;
  414.     if (guid == VIDEO_GUID && !goingvisible && __hiding_video) return FALSE;
  415.     if (guid == VIS_GUID && !goingvisible && __hiding_vis) return FALSE;
  416.     if (guid == VIDEO_GUID && goingvisible && __showing_video) return FALSE;
  417.     if (guid == VIS_GUID && goingvisible && __showing_vis) return FALSE;
  418.  
  419. #ifdef DEBUG
  420.     DebugString("--------------- onGetCancelComponent ----------------", 0);
  421.     DebugString(" GUID : " + guid, 0);
  422.     if (goingvisible) DebugString(" Going Visible", 0); else DebugString(" Going Invisible", 0);
  423.     DebugString(" Last Content : " + IntegerToString(getPrivateInt("winamp5", __myname+"State", CONTENT_VIS)), 0);
  424.     DebugString(" Drawer State : " + IntegerToString(getPrivateInt("winamp5", __myname+"OpenState", CLOSED)), 0);
  425.     DebugString("-----------------------------------------------------", 0);
  426. #endif
  427.  
  428.     if (!__main.isVisible()) return FALSE;
  429.  
  430.     int Window_Content=getPrivateInt("winamp5", __myname+"State", CONTENT_VIS);
  431.     int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  432.  
  433.     if (window_status == CLOSED) {
  434.         if (guid == VIDEO_GUID) {
  435.             if (__video_detach_attrib.getData() == "0") {
  436.                 if (goingvisible) {
  437.                     openDrawerForVideo();
  438.                     return TRUE;
  439.                 }
  440.             }
  441.         }
  442.         if (guid == VIS_GUID) {
  443.             if (__vis_detach_attrib.getData() == "0") {
  444.                 if (goingvisible) {
  445.                     openDrawerForVis();
  446.                     return TRUE;
  447.                 }
  448.             }
  449.         }
  450.     } else if (window_status == OPEN) {
  451.         if (goingvisible) {
  452.             if (guid == VIDEO_GUID && window_content == CONTENT_VIS) {
  453.                 if (__video_detach_attrib.getData() == "0") {
  454.                     window_content = CONTENT_VIDEO;
  455.                     drawer_hideVis();
  456.                     drawer_dc_showVideo();
  457.                     return TRUE;
  458.                 }
  459.             } else if (guid == VIS_GUID && window_content == CONTENT_VIDEO) {
  460.                 if (__vis_detach_attrib.getData() == "0") {
  461.                     window_content = CONTENT_VIS;
  462.                     drawer_disablePSOVC();
  463.                     drawer_hideVideo();
  464.                     drawer_dc_showVis();
  465.                     return TRUE;
  466.                 }
  467.             }
  468.         }
  469.     }
  470.     if (!goingvisible && window_status == OPEN) {
  471. #ifdef DEBUG
  472.         DebugString("closing " + guid, 0);
  473. #endif
  474.         if (guid == VIDEO_GUID && window_content == CONTENT_VIDEO) {
  475.             drawer_hideVideo();
  476.             drawer_reduceWindow(1);
  477.             return FALSE;
  478.         }
  479.         if (guid == VIS_GUID && window_content == CONTENT_VIS) {
  480.             drawer_hideVis();
  481.             if ((getStatus() == STATUS_PLAYING ||
  482.                 getStatus() == STATUS_PAUSED) &&
  483.                 isVideo() &&
  484.                 __video_detach_attrib.getData() == "0") {
  485.                 drawer_dc_showVideo();
  486.             } else {
  487.                 drawer_reduceWindow(1);
  488.             }
  489.             return FALSE;
  490.         }
  491.     }
  492. #ifdef DEBUG
  493.     DebugString("Went thru", 0);
  494. #endif
  495.     return FALSE;
  496. }
  497.  
  498. // -----------------------------------------------------------------------
  499. drawer_showVis() {
  500. #ifdef DEBUG
  501.     DebugString("drawer_showVis",0 );
  502. #endif
  503.     __showing_vis = 1;
  504.     setPrivateInt("winamp5", __myname+"OpenState", OPEN);
  505.     setPrivateInt("winamp5", __myname+"State", CONTENT_VIS);
  506.     GuiObject o = getVisWindowHolder();
  507.     if (o != NULL) { __bypasscancel = 1; o.show(); __bypasscancel = 0; }
  508. #ifdef DEBUG
  509.     else DebugString("vis object not provided (show)", 0);
  510. #endif
  511.     onShowVis();
  512.     __showing_vis = 0;
  513. }
  514.  
  515. // -----------------------------------------------------------------------
  516. drawer_hideVis() {
  517.     __callback_vis_show = 0;
  518. #ifdef DEBUG
  519.     DebugString("drawer_hideVis",0 );
  520. #endif
  521.     __hiding_vis = 1;
  522.     GuiObject o = getVisWindowHolder();
  523.     if (o != NULL) { __bypasscancel = 1; o.hide(); __bypasscancel = 0; }
  524. #ifdef DEBUG
  525.     else DebugString("video object not found (hide)", 0);
  526. #endif
  527.     onHideVis();
  528.     __hiding_vis = 0;
  529. }
  530.  
  531. // -----------------------------------------------------------------------
  532. drawer_showVideo() {
  533. #ifdef DEBUG
  534.     DebugString("drawer_showVideo",0 );
  535. #endif
  536.     __showing_video = 1;
  537.     setPrivateInt("winamp5", __myname+"OpenState", OPEN);
  538.     setPrivateInt("winamp5", __myname+"State", CONTENT_VIDEO);
  539.     GuiObject o = getVideoWindowHolder();
  540.     if (o != NULL) { __bypasscancel = 1; o.show(); __bypasscancel = 0; }
  541. #ifdef DEBUG
  542.     else DebugString("vis object not found (show)", 0);
  543. #endif
  544.     onShowVideo();
  545.     __showing_video = 0;
  546. }
  547.  
  548. // -----------------------------------------------------------------------
  549. drawer_hideVideo() {
  550.     __callback_video_show = 0;
  551. #ifdef DEBUG
  552.     DebugString("drawer_hideVideo",0 );
  553. #endif
  554.     __hiding_video = 1;
  555.     GuiObject o = getVideoWindowHolder();
  556.     if (o != NULL) { __bypasscancel = 1; o.hide(); __bypasscancel = 0; }
  557. #ifdef DEBUG
  558.     else DebugString("video object not found (hide)", 0);
  559. #endif
  560.     onHideVideo();
  561.     __hiding_video = 0;
  562. }
  563.  
  564. // -----------------------------------------------------------------------
  565. __callbackTimer.onTimer() {
  566.     stop();
  567.     int cvds = __callback_video_show;
  568.     int cvss = __callback_vis_show;
  569.     int cvdh = __callback_video_hide;
  570.     int cvsh = __callback_vis_hide;
  571.     __callback_video_show = 0;
  572.     __callback_vis_show = 0;
  573.     __callback_video_hide = 0;
  574.     __callback_vis_hide = 0;
  575.     if (cvds == 1) drawer_showVideo();
  576.     if (cvss == 1) drawer_showVis();
  577.     if (cvsh == 1) drawer_hideVis();
  578.     if (cvdh == 1) drawer_hideVideo();
  579. }
  580.  
  581. // -----------------------------------------------------------------------
  582. drawer_dc_showVideo() {
  583.     __callback_video_show = 1;
  584.     __callback_video_hide = 0;
  585.     __callbackTimer.start();
  586. }
  587.  
  588. // -----------------------------------------------------------------------
  589. drawer_dc_showVis() {
  590.     __callback_vis_show = 1;
  591.     __callback_vis_hide = 0;
  592.     __callbackTimer.start();
  593. }
  594.  
  595. // -----------------------------------------------------------------------
  596. drawer_dc_hideVideo() {
  597.     __callback_video_show = 0;
  598.     __callback_video_hide = 1;
  599.     __callbackTimer.start();
  600. }
  601.  
  602. // -----------------------------------------------------------------------
  603. drawer_dc_hideVis() {
  604.     __callback_vis_show = 0;
  605.     __callback_vis_hide = 1;
  606.     __callbackTimer.start();
  607. }
  608.  
  609. // -----------------------------------------------------------------------
  610. drawer_showWindowContent() {
  611.     int lastWindowContent=getPrivateInt("winamp5", __myname+"State", 2);
  612. #ifdef DEBUG
  613.     DebugString("drawer_showWindowContent = " + IntegerToString(lastWindowContent), 0);
  614. #endif
  615.     if (lastWindowContent==CONTENT_VIDEO) drawer_dc_showVideo();
  616.     if (lastWindowContent==CONTENT_VIS) drawer_dc_showVis();
  617. }
  618.  
  619. // -----------------------------------------------------------------------
  620. drawer_hideWindowContent() {
  621.     int lastWindowContent=getPrivateInt("winamp5", __myname+"State", 2);
  622. #ifdef DEBUG
  623.     DebugString("drawer_hideWindowContent = " + IntegerToString(lastWindowContent), 0);
  624. #endif
  625.     /*if (lastWindowContent==CONTENT_VIDEO)*/ drawer_hideVideo();
  626.     /*if (lastWindowContent==CONTENT_VIS)*/ drawer_hideVis();
  627. }
  628.  
  629. // -----------------------------------------------------------------------
  630. OpenDrawerForVideo() {
  631.     setPrivateInt("winamp5", __myname+"State", CONTENT_VIDEO);
  632.     drawer_expandWindow(1);
  633. }
  634.  
  635. // -----------------------------------------------------------------------
  636. OpenDrawerForVis() {
  637.     setPrivateInt("winamp5", __myname+"State", CONTENT_VIS);
  638.     drawer_expandWindow(1);
  639. }
  640.  
  641. // -----------------------------------------------------------------------
  642. OpenDrawerForNothing() {
  643.     setPrivateInt("winamp5", __myname+"State", CONTENT_NOTHING);
  644.     drawer_expandWindow(1);
  645. }
  646.  
  647. // -----------------------------------------------------------------------
  648. __main.onResize(int x, int y, int w, int h) {
  649.     if (!isGoingToTarget() && !__isinited) {
  650.         __isinited = 1;
  651.         if (h > getDrawerClosedHeight()) { setPrivateInt("winamp5", __myname+"OpenState", OPEN); drawer_expandWindow(0); }
  652.         else setPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  653.     }
  654. }
  655.  
  656. // -----------------------------------------------------------------------
  657. __main.onUserResize(int x, int y, int w, int h) {
  658.     int window_status=getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  659.     if (window_status == OPEN) {
  660.         int h = getHeight();
  661.         if (h != getDrawerClosedHeight()) {
  662. #ifdef DEBUG
  663.             DebugString("h = "+integerTostring(h), 0);
  664. #endif
  665.             if (!__maximized)
  666.               setPrivateInt("winamp5", __myname+"Height", h);
  667.         }
  668.     } else if (window_status == CLOSED) {
  669.       int h = getDrawerOpenAutoHeight(w);
  670.       if (h != -1) {
  671.         setPrivateInt("winamp5", __myname+"Height", h);
  672.       }
  673.     }
  674.     if (__maximized) {
  675.       __maximized = 0;
  676.       setPrivateInt("winamp5", __myname+"Maximized", 0);
  677.       onCancelMaximize();
  678.     }
  679. }
  680.  
  681. // -----------------------------------------------------------------------
  682. switchToVideo() {
  683.     if (__callbackTimer.isRunning()) return;
  684.     if (__callbackTimer2.isRunning()) return;
  685.     if (__tempDisable.isRunning()) return;
  686.     __tempDisable.start();
  687.     drawer_hideVis();
  688.     drawer_showVideo();
  689. }
  690.  
  691. // -----------------------------------------------------------------------
  692. switchToVis() {
  693.     if (__callbackTimer.isRunning()) return;
  694.     if (__callbackTimer2.isRunning()) return;
  695.     if (__tempDisable.isRunning()) return;
  696.     __tempDisable.start();
  697.     drawer_disablePSOVC();
  698.     drawer_hideVideo();
  699.     drawer_showVis();
  700. }
  701.  
  702. // -----------------------------------------------------------------------
  703. __tempDisable.onTimer() {
  704.     stop();
  705. }
  706.  
  707. // -----------------------------------------------------------------------
  708. detachVis() {
  709.     if (__tempDisable.isRunning()) return;
  710.     __tempDisable.start();
  711.     __vis_detach_attrib.setData("1");
  712. }
  713.  
  714. // -----------------------------------------------------------------------
  715. detachVideo() {
  716.     if (__tempDisable.isRunning()) return;
  717.     __tempDisable.start();
  718.     __video_detach_attrib.setData("1");
  719. }
  720.  
  721. // -----------------------------------------------------------------------
  722. attachVis() {
  723.     if (__tempDisable.isRunning()) return;
  724.     __tempDisable.start();
  725.     __vis_detach_attrib.setData("0");
  726. }
  727.  
  728. // -----------------------------------------------------------------------
  729. attachVideo() {
  730.     if (__tempDisable.isRunning()) return;
  731.     __tempDisable.start();
  732.     __video_detach_attrib.setData("0");
  733. }
  734.  
  735. // -----------------------------------------------------------------------
  736. __video_detach_attrib.onDataChanged() {
  737. #ifdef DEBUG
  738.     DebugString("detach video changed", 0);
  739. #endif
  740.     if (getData() == "1") {
  741.         drawer_doDetachVideo();
  742.         onDetachVideo();
  743.     } else {
  744.         if (getData() == "0") {
  745.             drawer_doAttachVideo();
  746.             onAttachVideo();
  747.         }
  748.     }
  749. }
  750.  
  751. // -----------------------------------------------------------------------
  752. __vis_detach_attrib.onDataChanged() {
  753. #ifdef DEBUG
  754.     DebugString("detach vis changed", 0);
  755. #endif
  756.     if (getData() == "1") {
  757.         drawer_doDetachVis();
  758.         onDetachVis();
  759.     } else {
  760.         if (getData() == "0") {
  761.             drawer_doAttachVis();
  762.             onAttachVis();
  763.         }
  764.     }
  765. }
  766.  
  767. // -----------------------------------------------------------------------
  768. drawer_doDetachVideo() {
  769.     int wasvisible = isNamedWindowVisible(VIDEO_GUID);
  770.     int lastWindowContent=getPrivateInt("winamp5", __myname+"State", 2);
  771.     int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  772.     if (!wasvisible) return;
  773.     if (lastWindowContent != CONTENT_VIDEO) return;
  774.     if (window_status == OPEN) {
  775.         drawer_disablePSOVC();
  776.         drawer_reduceWindow(1);
  777.     }
  778.     drawer_dc_linkup_showVideo();
  779. }
  780.  
  781. // -----------------------------------------------------------------------
  782. drawer_doDetachVis() {
  783.     int lastWindowContent=getPrivateInt("winamp5", __myname+"State", 2);
  784.     int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  785.     if (lastWindowContent != CONTENT_VIS) return;
  786.     int wasvisible = isNamedWindowVisible(VIS_GUID);
  787.     if (!wasvisible) return;
  788.     if (window_status == OPEN) {
  789.         drawer_hideVis();
  790.         if ((getStatus() == STATUS_PLAYING ||
  791.              getStatus() == STATUS_PAUSED) && isVideo() &&
  792.              __video_detach_attrib.getData() == "0") {
  793.              setPrivateInt("winamp5", __myname+"State", CONTENT_VIDEO);
  794.             drawer_dc_showVideo();
  795.         } else {
  796.             drawer_reduceWindow(1);
  797.         }
  798.     }
  799.     drawer_dc_linkup_showVis();
  800. }
  801.  
  802. // -----------------------------------------------------------------------
  803. drawer_doAttachVideo() {
  804.     drawer_disablePSOVC();
  805.     int wasvisible = isNamedWindowVisible(VIDEO_GUID);
  806.     if (wasvisible) {
  807.         hideNamedWindow(VIDEO_GUID);
  808.         int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  809.         int window_content=getPrivateInt("winamp5", __myname+"State", 2);
  810.         if (window_content == CONTENT_VIS) drawer_hideVis();
  811.         if (window_status == CLOSED) openDrawerForVideo();
  812.         else drawer_dc_showVideo();
  813.     }
  814. }
  815.  
  816. // -----------------------------------------------------------------------
  817. drawer_doAttachVis() {
  818.     drawer_disablePSOVC();
  819.     int wasvisible = isNamedWindowVisible(VIS_GUID);
  820.     if (wasvisible) {
  821.         hideNamedWindow(VIS_GUID);
  822.         int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  823.         int window_content=getPrivateInt("winamp5", __myname+"State", 2);
  824.         if (window_content == CONTENT_VIDEO) drawer_hideVideo();
  825.         if (window_status == CLOSED) openDrawerForVis();
  826.         else drawer_dc_showVis();
  827.     }
  828. }
  829.  
  830. // -----------------------------------------------------------------------
  831. __callbackTimer2.onTimer() {
  832.     stop();
  833.     if (__callback2_what == DETACHED_VIDEO) drawer_linkup_showVideo();
  834.     if (__callback2_what == DETACHED_VIS) drawer_linkup_showVis();
  835. }
  836.  
  837. // -----------------------------------------------------------------------
  838. drawer_dc_linkup_showVis() {
  839.     __callback2_what = DETACHED_VIS;
  840.     __callbackTimer2.start();
  841. }
  842.  
  843. // -----------------------------------------------------------------------
  844. drawer_dc_linkup_showVideo() {
  845.     __callback2_what = DETACHED_VIDEO;
  846.     __callbackTimer2.start();
  847. }
  848.  
  849. // -----------------------------------------------------------------------
  850. drawer_linkup_showVis() {
  851. #ifdef DEBUG
  852.     DebugString("show detached vis",0 );
  853. #endif
  854.     showWindow(VIS_GUID, "", 0);
  855. }
  856.  
  857. // -----------------------------------------------------------------------
  858. drawer_linkup_showVideo() {
  859. #ifdef DEBUG
  860.     DebugString("show detached video",0 );
  861. #endif
  862.     showWindow(VIDEO_GUID, "", 0);
  863.     drawer_enablePSOVC();
  864. }
  865.  
  866. // -----------------------------------------------------------------------
  867. drawer_disablePSOVC() {
  868. #ifdef DEBUG
  869.     DebugString("disabling stop on video close",0 );
  870. #endif
  871.     ConfigItem item = Config.getItem(SKINTWEAKS_CFGPAGE);
  872.     if (item) {
  873.         ConfigAttribute attr = item.getAttribute("Prevent video playback Stop on video window Close");
  874.         if (attr) attr.setData("1");
  875.     }
  876.     __PSOVCTimer.start();
  877. }
  878.  
  879. // -----------------------------------------------------------------------
  880. drawer_enablePSOVC() {
  881. #ifdef DEBUG
  882.     DebugString("enabling stop on video close",0 );
  883. #endif
  884.     __PSOVCTimer.stop();
  885.     ConfigItem item = Config.getItem(SKINTWEAKS_CFGPAGE);
  886.     if (item) {
  887.         ConfigAttribute attr = item.getAttribute("Prevent video playback Stop on video window Close");
  888.         if (attr) attr.setData("0");
  889.     }
  890. }
  891.  
  892. // -----------------------------------------------------------------------
  893. __PSOVCTimer.onTimer() {
  894.     drawer_enablePSOVC();
  895. }
  896.  
  897. // -----------------------------------------------------------------------
  898. __maincontainer.onBeforeSwitchToLayout(Layout oldl, Layout newl) {
  899.     int window_status =getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  900.     int window_content=getPrivateInt("winamp5", __myname+"State", 2);
  901.     if (oldl == __main && window_status == OPEN && window_content == CONTENT_VIDEO && getStatus() == STATUS_PLAYING && isVideo()) {
  902.         drawer_disablePSOVC();
  903.         __windowshade_openvid = 1;
  904.     }
  905.     if (oldl == __main && window_status == OPEN && window_content == CONTENT_VIS) {
  906.         __windowshade_openvis = 1;
  907.     }
  908. }
  909.  
  910. // -----------------------------------------------------------------------
  911. __maincontainer.onSwitchToLayout(Layout newl) {
  912.     // these do not call drawer_doDetachVis or drawer_doDetachVideo but showDetachVis and showDetachVideo so that the change is temporary
  913.     if (__windowshade_openvid) {
  914.         __windowshade_openvid = 0;
  915.         drawer_linkup_showVideo(); 
  916.     }
  917.     if (__windowshade_openvis) {
  918.         __windowshade_openvis = 0;
  919.         drawer_linkup_showVis(); 
  920.     }
  921. }
  922.  
  923. // -----------------------------------------------------------------------
  924. Int getDrawerState() {
  925.     return getPrivateInt("winamp5", __myname+"OpenState", CLOSED);
  926. }
  927.  
  928. // -----------------------------------------------------------------------
  929. Int getDrawerContent() {
  930.     return getPrivateInt("winamp5", __myname+"State", CONTENT_VIS);
  931. }
  932.  
  933. // -----------------------------------------------------------------------
  934. maximizeWindow() {
  935.   __oldx=__main.getGuiX();
  936.   __oldy=__main.getGuiY();
  937.   __oldw=__main.getGuiW();
  938.   __oldh=__main.getGuiH();
  939.  
  940.   setPrivateInt("winamp5", __myname+"ox", __oldx);
  941.   setPrivateInt("winamp5", __myname+"oy", __oldy);
  942.   setPrivateInt("winamp5", __myname+"ow", __oldw);
  943.   setPrivateInt("winamp5", __myname+"oh", __oldh);
  944.  
  945.   drawer_doMaximizeWindow(1);
  946. }
  947.  
  948. // -----------------------------------------------------------------------
  949. drawer_doMaximizeWindow(int notif) {
  950.   int vx=getViewportLeft();
  951.   int vy=getViewportTop();
  952.   int vw=getViewportWidth();
  953.   int vh=getViewportHeight();
  954.  
  955.   if (notif) onBeforeMaximize();
  956.   __maximized = 1;
  957.   setPrivateInt("winamp5", __myname+"Maximized", 1);
  958.   __main.resize(vx, vy, vw, vh+__main.getSnapAdjustBottom());
  959.   if (notif) onAfterMaximize();
  960. }
  961.  
  962. // -----------------------------------------------------------------------
  963. __main.onSnapAdjustChanged() {
  964.   if (__maximized)
  965.     drawer_doMaximizeWindow(0);
  966. }
  967.  
  968. // -----------------------------------------------------------------------
  969. restoreWindow() {
  970.     onBeforeRestore();
  971.     __maximized = 0;
  972.     setPrivateInt("winamp5", __myname+"Maximized", 0);
  973.     __main.resize(__oldx, __oldy, __oldw, __oldh);
  974.     onAfterRestore();
  975. }
  976.  
  977. // -----------------------------------------------------------------------
  978. // default events implementations - override them in your script
  979. // -----------------------------------------------------------------------
  980. onBeforeOpeningDrawer() {}
  981. onBeforeClosingDrawer() {}
  982. onDoneOpeningDrawer() {}
  983. onDoneClosingDrawer() {}
  984. onShowVis() {}
  985. onHideVis() {}
  986. onShowVideo() {}
  987. onHideVideo() {}
  988. onAttachVideo() {}
  989. onDetachVideo() {}
  990. onAttachVis() {}
  991. onDetachVis() {}
  992. onBeforeMaximize() {}
  993. onBeforeRestore() {}
  994. onAfterMaximize() {}
  995. onAfterRestore() {}
  996. onCancelMaximize() {}
  997.